<?php
/**
 * Created by PhpStorm.
 * User: wangjiangtao
 * Date: 2022/5/25
 * Time: 15:39
 */

namespace App\Http\Controllers\Api;


use App\Model\Statistics;
use Illuminate\Http\Request;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Facades\DB;
use App\Model\OperationLogs;

class StatisticsController extends BaseController
{

    protected $model = null;
    /**
     * @param Request $request
     */
    public function __construct(Request $request)
    {
        parent::__construct($request);
        $this->model = new Statistics();
    }

    //每日统计
    public function statDaily(Request $request){
        return $this->toJson(self::SUCCESS, $this->model->statDaily($request));
    }

    /**
     * 每日房间消费统计(主播数据)NEW
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     * @author 陈凯强
     */
    public function statDailyRoom(Request $request){
        $page = $request->get('page',1);
        $limit = $request->get('limit',10);
        $roomId = $request->get('roomId');
        $unionId = $request->get('unionId');
        $union_name = $request->get('unionName');
        $room_name = $request->get('roomName');
        $startTime = $request->get('created_st');
        $endTime = $request->get('created_ed');
        //查询数据
        $result = $this->model->getDaiylRoom2NewV2($page,$limit,$roomId,$startTime,$endTime,$unionId, $union_name, $room_name);
        return $this->toJson(self::SUCCESS, $result);

    }
    /**
     * 每日房间消费统计(主播数据)NEW
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     * @author 陈凯强
     */
    public function statDailyRoom2NewV2(Request $request){
        $page = $request->get('page',1);
        $limit = $request->get('limit',10);
        $roomId = $request->get('roomId');
        $unionId = $request->get('unionId');
        $union_name = $request->get('unionName');
        $room_name = $request->get('roomName');
        $startTime = $request->get('created_st');
        $endTime = $request->get('created_ed');
        //查询数据
        $result = $this->model->getDaiylRoom2NewV2($page,$limit,$roomId,$startTime,$endTime,$unionId, $union_name, $room_name);
        return $this->toJson(self::SUCCESS, $result);

    }

    /**
     * 每日房间消费统计(主播数据)NEW
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     * @author 陈凯强
     */
    public function statDailyRoom2(Request $request){
//        $dayDate = date('Y-m-d', time());
//        $dayStart = strtotime($dayDate.' 00:00:00');
//        $dayEnd = strtotime($dayDate.' 23:59:59');

        $startTime = $request->get('created_st');
        $endTime = $request->get('created_ed');
        $dayStart = strtotime($startTime);
        $dayEnd = strtotime($endTime);
        $page = $request->get('page',1);
        $limit = $request->get('limit',10);
        $roomId = $request->get('roomId');
        $startTime = date('Y-m-d',$dayStart);
        $endTime = date('Y-m-d',$dayEnd);
        $unionId = $request->get('unionId');
        $union_name = $request->get('unionName');
        $room_name = $request->get('roomName');

        //查询数据
        $result = $this->model->getDaiylRoom2($page,$limit,$roomId,$startTime,$endTime,$unionId,$union_name,$room_name);
        return $this->toJson(self::SUCCESS, $result);

    }    
    
    public function statDailyRoom2New(Request $request){
//        $dayDate = date('Y-m-d', time());
//        $dayStart = strtotime($dayDate.' 00:00:00');
//        $dayEnd = strtotime($dayDate.' 23:59:59');

        $startTime = $request->get('created_st');
        $endTime = $request->get('created_ed');
        $dayStart = strtotime($startTime);
        $dayEnd = strtotime($endTime);
        $page = $request->get('page',1);
        $limit = $request->get('limit',10);
        $roomId = $request->get('roomId');
        $startTime = date('Y-m-d',$dayStart);
        $endTime = date('Y-m-d',$dayEnd);
        $unionId = $request->get('unionId');
        $union_name = $request->get('unionName');
        $room_name = $request->get('roomName');

        //查询数据
        $result = $this->model->getDaiylRoom2New($page,$limit,$roomId,$startTime,$endTime,$unionId,$union_name,$room_name);
        return $this->toJson(self::SUCCESS, $result);

    }

    /**
     * 每日房间统计(所有用户数据)
     */
    public function statDailyRoomByall(Request $request){
        $page = $request->get('page',1);
        $limit = $request->get('limit',10);
        $roomUid = $request->get('roomUid',0); //房间uid
        $roomName = $request->get('roomName','');//房间名称
        $unuserUid = $request->get('unionUserUid');//公会长Uid
        $union_name = $request->get('union_name','');//公会名称
        $startTime = $request->get('created_st');
        $endTime = $request->get('created_ed');
        //查询数据
        $result = $this->model->getDaiylRoomAll($page, $limit, $roomUid, $roomName, $unuserUid, $union_name, $startTime, $endTime);
        return $this->toJson(self::SUCCESS, $result);
    }

    //小游戏每日统计
    public function gameDayStatistics(Request $request){
        return $this->toJson(self::SUCCESS, $this->model->gameDayStatistics($request));
    }

    //小游戏每日房间统计
    public function gameRoomDayStatistics(Request $request){
        return $this->toJson(self::SUCCESS, $this->model->gameRoomDayStatistics($request));
    }

    //房间团战每日团战次数统计
    public function roomPkStatistics(Request $request){
        return $this->toJson(self::SUCCESS, $this->model->roomPkStatistics($request));
    }

    //房间团战pk详情查询
    public function roomPkList(Request $request){
        return $this->toJson(self::SUCCESS, $this->model->roomPkList($request));
    }

    //公会房间周结算列表
    public function unionRoomWeekRewardList(Request $request){
        return $this->toJson(self::SUCCESS, $this->model->unionRoomWeekRewardList($request));
    }
    public function unionRoomWeekRewardListV2(Request $request){
        return $this->toJson(self::SUCCESS, $this->model->unionRoomWeekRewardListV2($request));
    }

    //娱乐等级整体数据
    public function gameRankStat(Request $request){
        return $this->toJson(self::SUCCESS, $this->model->gameRankStat($request));
    }

    //娱乐等级奖励下发明细
    public function gameRankRewardStat(Request $request){
        return $this->toJson(self::SUCCESS, $this->model->gameRankRewardStat($request));
    }

    //幸运礼物统计数据概述
    public function luckGiftAllStatistics(Request $request){
        return $this->toJson(self::SUCCESS, $this->model->luckGiftAllStatistics($request));
    }

    //幸运礼物统计用户统计
    public function luckGiftUserStatistics(Request $request){
        return $this->toJson(self::SUCCESS, $this->model->luckGiftUserStatistics($request));
    }

    //幸运礼物统计抽奖记录
    public function luckGiftDrawLog(Request $request){
        return $this->toJson(self::SUCCESS, $this->model->luckGiftDrawLog($request));
    }

    //幸运礼物统计抽奖记录明细
    public function luckGiftDraInfoList(Request $request){
        return $this->toJson(self::SUCCESS, $this->model->luckGiftDraInfoList($request));
    }

    //极妙抽奖奖池统计
    public function getJmRewardPool(Request $request){
        $res = $this->model->getJmRewardPool($request->all());
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //极妙抽奖抽奖记录
    public function getJmRewardList(Request $request){
        return $this->toJson(self::SUCCESS, $this->model->getJmRewardList($request));
    }

    //2023疯狂双十一贝壳礼包数据概述
    public function ssy2023ShellBagStat(Request $request){
        return $this->toJson(self::SUCCESS, $this->model->ssy2023ShellBagStat($request));
    }

    //2023疯狂双十一折扣礼包数据概述
    public function ssy2023RateBagStat(Request $request){
        return $this->toJson(self::SUCCESS, $this->model->ssy2023RateBagStat($request));
    }

    //2023疯狂双十一折扣礼物数据概述
    public function ssy2023GiftStat(Request $request){
        return $this->toJson(self::SUCCESS, $this->model->ssy2023GiftStat($request));
    }

    //2023双12贝壳礼包数据概述
    public function sse2023ShellBagStat(Request $request){
        return $this->toJson(self::SUCCESS, $this->model->sse2023ShellBagStat($request));
    }

    //2023双12折扣礼包数据概述
    public function sse2023RateBagStat(Request $request){
        return $this->toJson(self::SUCCESS, $this->model->sse2023RateBagStat($request));
    }

    //2023双12折扣礼物数据概述
    public function sse2023GiftStat(Request $request){
        return $this->toJson(self::SUCCESS, $this->model->sse2023GiftStat($request));
    }

    //2023双旦节榜上有名主播榜
    public function sdj2023RankUser(Request $request){
        return $this->toJson(self::SUCCESS, $this->model->sdj2023RankUser($request));
    }

    //2023双旦节榜上有名富豪榜
    public function sdj2023RankRich(Request $request){
        return $this->toJson(self::SUCCESS, $this->model->sdj2023RankRich($request));
    }

    //2023双旦节榜上有名房间榜
    public function sdj2023RankRoom(Request $request){
        return $this->toJson(self::SUCCESS, $this->model->sdj2023RankRoom($request));
    }

    //2023双旦节好运连连每日数据
    public function sdj2023HyllDatStat(Request $request){
        return $this->toJson(self::SUCCESS, $this->model->sdj2023HyllDatStat($request));
    }

    //留言板列表
    public function lybList(Request $request){
        return $this->toJson(self::SUCCESS, $this->model->lybList($request));
    }

    //留言板人工审核
    public function lybAudit(Request $request){
        $res = $this->model->lybAudit($request->all());
        if($res['code'] == self::SUCCESS) {
            OperationLogs::createData($request, OperationLogs::ACTIVITY, '留言板人工审核');
        }
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //按照每小时房间统计查看流水
    public function roomDataByHour(Request $request){
        $roomId = $request->get('room_id',0);//房间id
        $startTime = $request->get('created_st',0);//开始时间
        $endTime = $request->get('created_ed',0);//结束时间
        if(empty($roomId) || empty($startTime) || empty($endTime)){
            $this->toJson(self::PARAM_ERROR,[],'检查参数room_id,start_time,end_time');
        }
        $res = $this->model->roomDataByHour($roomId, $startTime, $endTime);
        return $this->toJson(self::SUCCESS,$res);
    }

    //玩法汇总数据
    public function gameplaySumStatList(Request $request){
        return $this->toJson(self::SUCCESS, $this->model->gameplaySumStatList($request));
    }

    //玩法汇总(同设备)
    public function gameplaySumStatListChild(Request $request){
        return $this->toJson(self::SUCCESS, $this->model->gameplaySumStatListChild($request));
    }

    //主播私信数量列表
    public function getIdentityMsgStatisticsList(Request $request){
        return $this->toJson(self::SUCCESS, $this->model->getIdentityMsgStatisticsList($request));
    }

    //用户资产明细列表
    public function userWalletStatList(Request $request){
        return $this->toJson(self::SUCCESS, $this->model->userWalletStatList($request));
    }

}
